define(['jquery'],function($) {
  var reqSscs=function () {
    $.getJSON('../../data/sscs.json',function(responseText,responseState,responseObj){

          // console.log(responseText);
          jieXi(responseText);
        });
  }

  function jieXi(data) {
    // 获取到对应的标签
      var $left=$('.left');
      var $bianhuan=$('.bianhuan');
      // $bianhuan.addClass('bianhuan');

      // console.log($left,$bianhuan);
      var datas=data.data;
      var categories=datas.categories;
      var products=datas.products;

      for(var i=0; i<categories.length; i++){
          var $divCreate=$('<div></div>').text(categories[i].name);
          $divCreate.addClass(categories[i].id);

          $left.append($divCreate);
      }

      var $leftDivs=$left.children('div');
      // var num=$($leftDivs[0]).attr('class');
      //   var num=$(this).attr('class') || 104749;

        var num=104749;
      console.log(num);
    function goodsJieXi(num){
      $bianhuan.empty();
      // $('.'+ num ).css('background','url("./sscs/img/xuanzhong.jpg") left center no-repeat');

      for(var j=0; j<products[num].length; j++){
        var deltObj=products[num][j];
        // var deltObj=products.num[j];
        var imgsrc=deltObj.img;
        var keywords=deltObj.keywords;
        var newPrice=deltObj.partner_price;
        var oldPrice=deltObj.market_price;
        var weight=deltObj.specifics;
        var fuli=deltObj.pm_desc;

          var $divGood=$('<div></div>').html('<div class="ss-goods">'+
            '<div class="image">'+
              '<img src="' + imgsrc + '" />'+
            '</div>'+
            '<div class="delt">'+
              '<p class="ss-title">' + keywords + '</p>'+
              '<p class="ss-fuli">'+
                '<span class="ss-teshu">精选</span>'+
                '<span class="ss-maizeng">' + fuli +'</span></p>'+
              '<p class="ss-weight">' + weight + '</p>'+
              '<p class="ss-jieshao">'+
                '<span class="ss-newPrice">' +  newPrice + '</span>'+
                '<span class="ss-oldPrice">'+ oldPrice  + '</span>'+
              '</p>'+
              '<p class="ss-tianjia"><img src="./home/img/icon-jia.jpg"></p>'+
            '</div>'+
          '</div>');

          $bianhuan.append($divGood);
          $('.goods-content').html($bianhuan);

          // console.log($('.'+ num ));
      }
    }

    goodsJieXi(num);

    // $leftDivs.on('touchEvents.touchend',goodsJieXi);
    for(var k=0; k<$leftDivs.length; k++){
        // console.log($leftDivs[k]);

          $leftDivs[k].addEventListener('touchend',function () {
            var num=$(this).attr('class');

            $leftDivs.css('background','#f8f8f8');
            $(this).css({
              'background':'url("./sscs/img/xuanzhong.jpg") left center no-repeat',
              'backgroundColor':'#f8f8f8'
            });
            goodsJieXi(num);

          });
    }
  }


  return{
    reqSscs:reqSscs

  }
});
